package com.life.view;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.TitledBorder;

import com.life.constants.Constants;
import com.life.utils.ImageUtil;


public class SimulationPanel extends JPanel {

	 JButton playButton = new JButton();
	 JButton pauseButton = new JButton();
	 JButton stopButton = new JButton();
	 JButton recordButton = new JButton();
	 JSlider simulationSlider = new JSlider();
	 JSpinner speedSpinner = new JSpinner();
	 SpinnerNumberModel spinnerModel =
                     new SpinnerNumberModel();
	 JLabel playbackLabel = new JLabel("Playback");
	 JLabel speedLabel = new JLabel("Speed ("+Constants.SPEED_MINIMUM+":"+Constants.SPEED_MAXIMUM+")");
 
	 int startWidth = 10;
	 int startHeight = 20;
	 int distance = 3;
	 int wSize = 35;
	 int hSize = 45;
	 
	 public SimulationPanel()
	 {
		 WidgetRegistry reg = WidgetRegistry.getInstance();
		 
		 reg.put(Constants.PLAY_WIDGET,playButton);
		 reg.put(Constants.STOP_WIDGET,stopButton);
		 reg.put(Constants.PAUSE_WIDGET,pauseButton);
		 reg.put(Constants.RECORD_WIDGET,recordButton);
		 reg.put(Constants.SLIDER_WIDGET,simulationSlider);
		 reg.put(Constants.SPEED_WIDGET,speedSpinner);
		 
		 TitledBorder simulationBorder = new TitledBorder("Simulation Controls");
		 this.setBorder(simulationBorder);
		 
		 this.setLayout(null);
		 
		// recordButton.setBounds(startWidth,startHeight,wSize,hSize);
		// this.add(recordButton);
		 
		// startWidth = startWidth + wSize + distance;
		 playButton.setBounds(startWidth,startHeight,wSize,hSize);
		 this.add(playButton);
		 
		 startWidth = startWidth + wSize + distance;
		 pauseButton.setBounds(startWidth,startHeight,wSize,hSize);
		 this.add(pauseButton);
		 
		// startWidth = startWidth + wSize + distance;
		// stopButton.setBounds(startWidth,startHeight,wSize,hSize);
		// this.add(stopButton);
		 
		 simulationSlider.setValue(0);
		 
		 startWidth = startWidth + wSize + distance;
		 playbackLabel.setBounds(startWidth+10,startHeight-5,100,15);
		 simulationSlider.setBounds(startWidth,startHeight+10,wSize*12,hSize-5);
		 this.add(playbackLabel);
		 this.add(simulationSlider);
		 
		 
		 spinnerModel.setMaximum(new Integer(Constants.SPEED_MAXIMUM));
		 spinnerModel.setMinimum(new Integer(Constants.SPEED_MINIMUM));
		 spinnerModel.setStepSize(new Integer(Constants.SPEED_STEP));
		 spinnerModel.setValue(new Integer(Constants.SPEED_START));
		 speedSpinner.setModel(spinnerModel);
		 speedSpinner.setEnabled(true);
		 
		 startWidth = startWidth + (wSize * 12) + distance;
		 speedLabel.setBounds(startWidth,startHeight-10,100,15);
		 speedSpinner.setBounds(startWidth,startHeight+15,wSize+wSize,hSize-15);
		 this.add(speedLabel);
		 this.add(speedSpinner);
		 
		 
		
		 
		 playButton.setIcon(ImageUtil.getImageIcon(SimulationPanel.class,"com\\life\\view\\icons\\Play.gif"));
		 pauseButton.setIcon(ImageUtil.getImageIcon(SimulationPanel.class,"com\\life\\view\\icons\\Pause.gif"));
		// recordButton.setIcon(ImageUtil.getImageIcon(this.getClass(),"icons\\Record.gif"));
		// stopButton.setIcon(ImageUtil.getImageIcon(this.getClass(),"icons\\Stop.gif"));
		 
	 }
	 
	 
}
